home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{13E51000-A52B-11D0-86DA-00608CB9FBFB}#5.0#0"; "VCF15.OCX"
- Begin VB.Form frmGolfMain
- Caption = "VC Formula One Golf Demonstration"
- ClientHeight = 7695
- ClientLeft = 2280
- ClientTop = 1650
- ClientWidth = 10350
- Icon = "frmGolfMain.frx":0000
- LinkTopic = "Form1"
- ScaleHeight = 7695
- ScaleWidth = 10350
- Begin VB.PictureBox Picture1
- AutoSize = -1 'True
- Height = 2220
- Left = 960
- Picture = "frmGolfMain.frx":030A
- ScaleHeight = 2160
- ScaleWidth = 1620
- TabIndex = 10
- Top = 5280
- Width = 1680
- End
- Begin VB.CommandButton cmdModify
- Caption = "&Modify Person Entries"
- Height = 495
- Left = 3720
- TabIndex = 1
- Top = 7080
- Width = 1695
- End
- Begin VB.CommandButton cmdSaveAs
- Caption = "S&ave Scorecard As..."
- Height = 495
- Left = 1800
- TabIndex = 9
- Top = 4560
- Width = 1695
- End
- Begin VB.CommandButton cmdCard
- Caption = "G&et Scorecard..."
- Height = 495
- Left = 120
- TabIndex = 8
- Top = 4560
- Width = 1695
- End
- Begin VB.CommandButton cmdProcess
- Caption = "&Process and Display Handicaps"
- Height = 615
- Left = 3720
- Style = 1 'Graphical
- TabIndex = 7
- Top = 6480
- Width = 1695
- End
- Begin VB.CommandButton cmdUpdateScores
- Caption = "&Update Scores"
- Height = 495
- Left = 3720
- Style = 1 'Graphical
- TabIndex = 6
- Top = 6000
- Width = 1695
- End
- Begin VB.CommandButton cmdRemove
- Caption = "&Remove Player"
- Height = 495
- Left = 3720
- TabIndex = 4
- Top = 5520
- Width = 1695
- End
- Begin VB.CommandButton cmdSelect
- Caption = "&Select Players"
- Height = 495
- Left = 3720
- TabIndex = 3
- Top = 5040
- Width = 1695
- End
- Begin VB.CommandButton cmdGet
- Caption = "&Get Players"
- Height = 495
- Left = 3720
- TabIndex = 2
- Top = 4560
- Width = 1695
- End
- Begin VCF150Ctl.F1Book F1Players
- Height = 3015
- Left = 5640
- TabIndex = 5
- Top = 4560
- Width = 4575
- _ExtentX = 8070
- _ExtentY = 5318
- _0 = $"frmGolfMain.frx":0FAA
- _1 = $"frmGolfMain.frx":13B0
- _2 = $"frmGolfMain.frx":17B5
- _3 = $"frmGolfMain.frx":1BBA
- _4 = $"frmGolfMain.frx":1FBF
- _count = 5
- _ver = 1
- End
- Begin VCF150Ctl.F1Book f1Scores
- Height = 4335
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 10095
- _ExtentX = 17806
- _ExtentY = 7646
- _0 = $"frmGolfMain.frx":2314
- _1 = $"frmGolfMain.frx":2719
- _2 = $"frmGolfMain.frx":2B1F
- _3 = $"frmGolfMain.frx":2F24
- _4 = $"frmGolfMain.frx":3329
- _5 = $"frmGolfMain.frx":372E
- _6 = $"frmGolfMain.frx":3B33
- _7 = $"frmGolfMain.frx":3F38
- _8 = $"frmGolfMain.frx":433D
- _9 = $"frmGolfMain.frx":4742
- _10 = $"frmGolfMain.frx":4B47
- _11 = $"frmGolfMain.frx":4F4D
- _12 = $"frmGolfMain.frx":5352
- _13 = $"frmGolfMain.frx":5757
- _14 = $"frmGolfMain.frx":5B5C
- _15 = $"frmGolfMain.frx":5F61
- _16 = $"frmGolfMain.frx":6366
- _17 = $"frmGolfMain.frx":676B
- _18 = $"frmGolfMain.frx":6B70
- _19 = $"frmGolfMain.frx":6F75
- _20 = $"frmGolfMain.frx":737A
- _21 = $"frmGolfMain.frx":777F
- _22 = $"frmGolfMain.frx":7B84
- _23 = $"frmGolfMain.frx":7F89
- _24 = $"frmGolfMain.frx":838E
- _25 = $"frmGolfMain.frx":8793
- _26 = $"frmGolfMain.frx":8B98
- _27 = $"frmGolfMain.frx":8F9D
- _28 = $"frmGolfMain.frx":93A2
- _29 = $"frmGolfMain.frx":97A7
- _30 = $"frmGolfMain.frx":9BAC
- _31 = $"frmGolfMain.frx":9FB1
- _32 = $"frmGolfMain.frx":A3B6
- _33 = $"frmGolfMain.frx":A7BB
- _34 = $"frmGolfMain.frx":ABC0
- _count = 35
- _ver = 1
- End
- Begin VCF150Ctl.F1Book F1B
- Height = 1695
- Left = 3840
- TabIndex = 11
- Top = 2400
- Visible = 0 'False
- Width = 2055
- _ExtentX = 3625
- _ExtentY = 2990
- _0 = $"frmGolfMain.frx":AEC2
- _1 = $"frmGolfMain.frx":B2C8
- _2 = $"frmGolfMain.frx":B6CD
- _3 = $"frmGolfMain.frx":BAD2
- _4 = $"frmGolfMain.frx":BED7
- _count = 5
- _ver = 1
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Begin VB.Menu mnuHelp
- Caption = "&Help"
- Begin VB.Menu mnuHelpAbout
- Caption = "&About"
- End
- End
- Attribute VB_Name = "frmGolfMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub GetScores(ss As F1Book, ID As String)
- Dim pQuery As New F1ODBCQuery
- Dim retcode As Integer
- 'In this procedure, we clear the existing information and then query
- 'the Scores table to get all the scores for a particular person.
- '
- ss.ClearRange -1, -1, -1, -1, F1ClearAll
- With pQuery
- .QueryStr = "SELECT * FROM Scores WHERE ID='" & Trim$(ID) & "'"
- .SetColFormats = False
- .SetColNames = False
- .SetColWidths = False
- .SetMaxRC = False
- End With
- Call ss.ODBCQueryEx(pQuery, 1, 1, False)
- If ss.LastRow > 0 Then 'don't need to sort if no scores exist.
- ss.Sort3 1, 1, ss.LastRow, ss.LastCol, True, 7, 1, 0
- End If
- End Sub
- Private Sub Update_Handicap(lRow As Long, lCol As Long, ss As F1Book)
- Dim iRetCode%
- ss.Sort3 lRow, 57, lRow, lCol + 57, False, 1, 0, 0
- Select Case lCol
- Case 5, 6 ' Get 1 Lowest Score
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 57, False) & "),1)"
-
- Case 7, 8 ' Get 2 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 58, False) & "),1)"
-
- Case 9, 10 ' Get 3 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 59, False) & "),1)"
-
- Case 11, 12 ' Get 4 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 60, False) & "),1)"
-
- Case 12, 14 ' Get 5 lowest scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 61, False) & "),1)"
-
- Case 15, 16 ' Get 6 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 62, False) & "),1)"
-
- Case 17 ' Get 7 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 63, False) & "),1)"
-
- Case 18 ' Get 8 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 64, False) & "),1)"
-
- Case 19 ' Get 9 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 65, False) & "),1)"
-
- Case 20 ' Get 10 Lowest Scores
- ss.FormulaRC(lRow, 2) = "ROUNDDOWN(Average(" & ss.FormatRCNr(lRow, 57, False) & ":" & ss.FormatRCNr(lRow, 56, False) & "),1)"
- End Select
-
- End Sub
- Private Sub cmdCard_Click()
- Dim iRetCode%
- Dim sFileName$
- On Error GoTo CardCancel
- sFileName = f1Scores.OpenFileDlgEx("Get Existing Scorecards", 0)
- iRetCode = f1Scores.ReadEx(sFileName)
- CardCancel:
- If Err.Number = 20023 Then 'cancel was selected
- Exit Sub
- End If
- End Sub
- Private Sub cmdGet_Click()
- Dim pQuery As New F1ODBCQuery
- Dim i%
-
- Call GolfConnect(F1Players)
- With pQuery
- .QueryStr = "SELECT Persons.ID, Persons.FirstName, Persons.LastName, Persons.Handicap FROM Persons"
- .retcode = i
- .SetColFormats = False
- .SetColNames = False
- .SetColWidths = False
- .SetMaxRC = True
- End With
- F1Players.ODBCQueryEx pQuery, 1, 1, False
- F1Players.ODBCDisconnect
- End Sub
- Private Sub cmdModify_Click()
- frmPerson.Show 1
- End Sub
- Private Sub cmdProcess_Click()
- Dim ss As F1Book
- Dim iRetCode As Integer
- Dim lRow&, lCol&
- Dim wrkGolf As Workspace
- Dim dbsGolf As Database
- Dim rstGolfPersons As Recordset
- Dim rstGolfScores As Recordset
- Dim PersonsCount&, ScoresCount&
- Dim ScoresQuery$
- iRetCode = MsgBox("This may take a few minutes to run. Continue?", vbYesNo + vbQuestion, "Process/Update Handicaps")
- If iRetCode = vbNo Then Exit Sub
- frmSplash.Show
- frmSplash.lblNotes.Caption = "Adding a Sheet and getting info."
- frmSplash.Refresh
- Sleep (250)
- Set ss = f1Scores
- ss.InsertSheets 3, 1
- ss.Sheet = 3
- ss.SheetName(ss.Sheet) = "Handicap Info"
- GolfConnect ss
- 'Create Workspace
- Set wrkGolf = CreateWorkspace("VciGolf", "admin", "", dbUseJet)
- 'Open Golf MDB file
- Set dbsGolf = wrkGolf.OpenDatabase(App.Path & "\golf.mdb")
- 'Open Persons and Scores tables
- With dbsGolf
- Set rstGolfPersons = .OpenRecordSet("Persons")
- 'Set the column headers
- ss.ColText(1) = "ID"
- ss.ColText(2) = "Handicap"
- ss.ColText(3) = "FirstName"
- ss.ColText(4) = "LastName"
- ss.ColText(5) = "Differential"
-
- rstGolfPersons.MoveLast
- 'Loop through Records to Get ID, FName, & LName
- For PersonsCount = rstGolfPersons.RecordCount - 1 To 0 Step -1
-
- 'Put ID, FName, & LName in cells.
- ss.TextRC(PersonsCount + 1, 1) = rstGolfPersons.Fields("ID").Value
- ss.TextRC(PersonsCount + 1, 3) = rstGolfPersons.Fields("FirstName").Value
- ss.TextRC(PersonsCount + 1, 4) = rstGolfPersons.Fields("LastName").Value
-
- 'Select all score differentials where scores.id = current persons.id
- ScoresQuery = "SELECT Differential FROM Scores WHERE " & _
- "ID = '" & rstGolfPersons.Fields("ID").Value & _
- "' ORDER BY sDate"
- Set rstGolfScores = .OpenRecordSet(ScoresQuery)
-
- rstGolfScores.MoveLast
- 'Plug differentials into next 0 to 20 columns of current row.
- For ScoresCount = rstGolfScores.RecordCount - 1 To 0 Step -1
- ss.NumberRC(PersonsCount + 1, ScoresCount + 5) = rstGolfScores.Fields("Differential").Value
- rstGolfScores.MovePrevious
- Next ScoresCount
-
- rstGolfPersons.MovePrevious
- Next PersonsCount
-
- rstGolfPersons.Close
-
- End With
- dbsGolf.Close
- wrkGolf.Close
- 'Copy the range to a location outside the visible region.
- 'This will allow to sort/order the scores for easier calculations
- 'of the handicaps
- frmSplash.lblNotes.Caption = "Rearranging data to do Calculations"
- frmSplash.Refresh
- Call ss.CopyRangeEx(ss.Sheet, 1, 57, ss.LastRow, 76, ss.ss, ss.Sheet, 1, 5, ss.LastRow, 24)
- frmSplash.lblNotes.Caption = "Calculating the handicaps"
- frmSplash.Refresh
- For lRow = ss.LastRow To 1 Step -1
-
- For lCol = 3 To 23
- 'Get the number of scores the person has reported.
- If ss.TypeRC(lRow, lCol) = 0 Then
- lCol = lCol - 1
- Exit For
- End If
- Next lCol
-
- 'since the columns started on the 3rd column, subtracting 2 from lcol _
- will give the actual number of scores the person has. We cannot calculate _
- handicaps unless at least 5 scores have been posted.
- If lCol - 2 < 5 Then
- ss.TextRC(lRow, 2) = "N/A"
- Else
- Call Update_Handicap(lRow, lCol - 2, ss)
- 'After getting handicaps updated, need to update persons info w/ new _
- handicap
- iRetCode = ss.ODBCPrepareEx("UPDATE Persons SET Handicap=? WHERE ID=?")
- iRetCode = ss.ODBCBindParameterEx(1, 2, F1CDataDouble) 'Handicap
- iRetCode = ss.ODBCBindParameterEx(2, 1, F1CDataChar) 'ID
-
- iRetCode = ss.ODBCExecuteEx(lRow, lRow)
- End If
-
- Next lRow
-
- f1Scores.Sheet = 3
- f1Scores.SetColWidthAuto -1, 1, -1, 5, False ' the '-1' will set width to header if necessary
- f1Scores.SetSelection 1, 1, 1, 1
- Unload frmSplash
- End Sub
- Private Sub cmdRemove_Click()
- 'Deletes current row(s)
- f1Scores.EditDelete F1ShiftRows
- End Sub
- Private Sub cmdSaveAs_Click()
- Dim ss As F1BookView
- Dim pFileInfo As New F1FileSpec
- Dim i&
- Set ss = New F1BookView
- On Error GoTo f1Cancel
- 'Creating a Formula One BookView so the unwanted information _
- can be cleared and saved to disk without interupting _
- existing spreadsheet. Otherwise, copies and pastes would _
- need to be done to get it to work. This method will be more "behind the _
- scenes" so the user will be less likely to notice.
-
- 'Copy info from Spreadsheet to new F1BookView created _
- where f1Scores is the name of the existing Formula One workbook.
- ss.CopyAll f1Scores.ss
- 'set up file name and type info
- pFileInfo.Name = f1Scores.Title
- pFileInfo.Type = F1FileFormulaOne3
- 'check to make sure handicap info is not saved w/ scorecard
- For i = 1 To ss.NumSheets
- ss.Sheet = i
- If ss.SheetName(i) = "Handicap Info" Then
- ss.DeleteSheets i, 1
- Exit For
- End If
- Next i
- 'set the first sheet sheet to be current
- ss.Sheet = 1
- 'save the window settings w/ the workbook: Max/Min/Fixed..., _
- Allow..., Show..., active sheet, etc.
- ss.SaveWindowInfo
- 'clear out the current players
- ss.ClearRange 4, 1, 1000, 26, F1ClearValues
- 'Cannot use the save file dialog with a F1BookView _
- because there is no window
- f1Scores.SaveFileDlgEx "Save current scorecard information", pFileInfo
- ss.WriteEx pFileInfo.Name, pFileInfo.Type
- Exit Sub
- f1Cancel:
- If Err.Number = 20023 Then 'cancel was selected in save file dlg.
- Exit Sub
- Else
- Resume Next
- End If
- End Sub
- Private Sub cmdSelect_Click()
- Dim iSelCount%, i%, iType%
- Dim pr1&, pc1&, pr2&, pc2&, lCount&, lRow&
- Dim objSelection As F1RangeRef
- 'Initialize the Row variable from where the search will be started.
- lRow = 2
- 'Loop through to find the first empty row
- Do
- lRow = lRow + 1
- iType = f1Scores.TypeRC(lRow, 1)
- Loop Until iType = 0 'Empty cell
- f1Scores.Selection = "A" & Trim$(Str$(lRow))
- ' Get the selection
- iSelCount = F1Players.SelectionCount
- For i = 0 To iSelCount - 1
- 'F1Players.GetSelection i, pr1, pc1, pr2, pc2
- Set objSelection = F1Players.SelectionEx(i)
-
- 'since there can be more than one row per selection and/or _
- multiple selections, we need to not only get the total number _
- of selections, but each row(s) in each selection, if in fact _
- there are multiple selections.
- For lCount = objSelection.StartRow To objSelection.EndRow
- 'Set Players' names and handicaps on 'score card'
- f1Scores.TextRC(lRow, 1) = F1Players.TextRC(lCount, 1)
- f1Scores.EntryRC(lRow, 23) = F1Players.EntryRC(lCount, 4)
-
- lRow = lRow + 1
- Next lCount
- Next i
- 'Need to copy formulas down for the calculations, _
- formulas, and totals, if not on the first row of players
- f1Scores.AutoRecalc = False
- f1Scores.Repaint = False
- f1Scores.CopyRangeEx 1, 6, 11, lRow - 1, 11, f1Scores.ss, 1, 5, 11, 5, 11 'Front Nine
- f1Scores.CopyRangeEx 1, 6, 21, lRow - 1, 21, f1Scores.ss, 1, 5, 21, 5, 21 'Back Nine
- f1Scores.CopyRangeEx 1, 6, 22, lRow - 1, 22, f1Scores.ss, 1, 5, 22, 5, 22 'Total Gross score
- f1Scores.CopyRangeEx 1, 6, 24, lRow - 1, 24, f1Scores.ss, 1, 5, 24, 5, 24 'Net Score
- f1Scores.CopyRangeEx 1, 6, 25, lRow - 1, 25, f1Scores.ss, 1, 5, 25, 5, 25 'Rating
- f1Scores.CopyRangeEx 1, 6, 26, lRow - 1, 26, f1Scores.ss, 1, 5, 26, 5, 26 'Slope
- f1Scores.CopyRangeEx 1, 6, 27, lRow - 1, 27, f1Scores.ss, 1, 5, 27, 5, 27 'Date of round
- 'the ags sheet starts scores on row 4 instead of row 5, hence the "lRow - 1" below
- f1Scores.CopyRangeEx 2, 5, 1, lRow - 2, 27, f1Scores.ss, 2, 4, 1, 4, 27 'formulas on AGS
- f1Scores.Repaint = True
- f1Scores.AutoRecalc = True
- End Sub
- Private Sub cmdUpdateScores_Click()
- Dim ss As F1Book
- Dim lRow&, LastRow&
- Dim lCount&
- Dim iRetCode%
- Dim pQuery As F1ODBCQuery
- Dim sPrepare$
- Me.MousePointer = vbHourglass
- frmSplash.Show
- frmSplash.lblNotes.Caption = "Updating Scores"
- Sleep (250)
- 'Attach View so that action can be done behind the scenes w/o user noticing
- Set ss = F1B
- 'ss.InitTable
- ss.Attach f1Scores.Title
- 'Check to make sure a sheet did not get inserted before 'Adg. Gross Scores' Sheet
- 'then set its information into the database fields.
- For lCount = 1 To ss.NumSheets
- ss.Sheet = lCount
- If ss.SheetName(lCount) = "Adjusted Gross Scores" Then
- ss.SetSelection 4, 1, 4, 1
- Exit For
- End If
- Next lCount
- 'check to see if there are scores to udpate.
- If ss.TypeRC(4, 1) = 0 Then
- MsgBox "There are no scores to update.", vbOKOnly, "Update Score"
- Unload frmSplash
- Me.Refresh
- Exit Sub
- End If
- 'Connect AGS sheet to our Golf DB
- GolfConnect ss
- LastRow = ss.LastRow
- 'Insert New sheet and connect it to our Golf db. This sheet will be used to verify and
- 'update up to 20 scores. If there are 20 scores, the newest score will replace
- 'the oldest score.
- ss.InsertSheets 3, 1
- ss.Sheet = 3
- GolfConnect ss
-
- For lRow = 4 To LastRow
-
- If ss.TypeSRC(2, lRow, 1) <> 0 Then 'score info is most likely available
- frmSplash.lblNotes.Caption = "Updating Row " & Str$(lRow - 3)
- frmSplash.Refresh
- ss.SetSelection lRow, 1, lRow, 1
- Call GetScores(ss, ss.TextSRC(2, lRow, 1))
-
- 'need to check to see how many scores are in the db for the particular _
- person as the handicap is determined on at least five scores and not _
- than 20 scores. In the GetScores procedure, the scores were sorted by _
- date so that the
- If ss.LastRow < 20 Then
- ss.Sheet = lCount
- 'Add new score to scores table
- sPrepare = "INSERT INTO Scores (ID, AdjScore, CourseRating, Slope, Differential, sDate) VALUES (?, ?, ?, ?, ?, ?)"
- Else
- ss.Sheet = lCount
- 'replace oldest score w/ newest one.
- sPrepare = "UPDATE Scores SET ID=?, AdjScore=?, CourseRating=?, Slope=?, Differential=?, sDate=? WHERE ScoreID='" & ss.TextSRC(3, 1, 1) & "'"
- End If
-
- iRetCode = ss.ODBCPrepareEx(sPrepare)
- iRetCode = ss.ODBCBindParameterEx(1, 1, F1CDataChar) 'ID
- iRetCode = ss.ODBCBindParameterEx(2, 22, F1CDataDouble) 'AdjScore (Adjusted)
- iRetCode = ss.ODBCBindParameterEx(3, 24, F1CDataDouble) 'Course Rating
- iRetCode = ss.ODBCBindParameterEx(4, 25, F1CDataLong) 'Slope
- iRetCode = ss.ODBCBindParameterEx(5, 26, F1CDataDouble) 'Differential
- iRetCode = ss.ODBCBindParameterEx(6, 27, F1CDataDate) 'Date of Round.
-
- iRetCode = ss.ODBCExecuteEx(lRow, lRow)
- End If
- ss.Sheet = 3
- Next lRow
- 'disconnect from the newly created sheet
- ss.Sheet = 3
- ss.ODBCDisconnect
- 'disconnect from scores (AGS) sheet
- ss.Sheet = lCount
- ss.ODBCDisconnect
- 'Delete newly create sheet
- ss.DeleteSheets 3, 1
- ss.Attach ""
- Unload frmSplash
- Me.MousePointer = vbDefault
- End Sub
- Private Sub mnuFileExit_Click()
- End
- End Sub
- Private Sub mnuHelpAbout_Click()
- frmHelp.Show 1
- End Sub
-